Tutorial Part II:  The Film Catalog

Creating a customized film folder viewer

In a sense, you have completed a rudimentary Film Catalog.  You can add, delete, and navigate between  films using the pop-up menu.  However, it would be even better to have a more customized way to view your film database.

You will create an new object (Film Catalog) for viewing film entries.  The bottom part of Film Catalog will display a single film, the top part will have controls and status information.

•
Close all floating windows except Folders.
•
Using the Utilities menu, create a new class named Film Catalog.

Change the aligner to have 2 rows and 1 column.

•
Command-click on the Film Catalog’s aligner.
•
Choose View Options... from the pop-up menu.
•
Choose Aligner Dimensions from the pop-up menu.
•
Change Rows to 2 and Columns to 1.  Click Save & Close.

Add an aligner to the top part of the form to hold the various controls.

•
Insert a new aligner  in the upper portion of the aligner.
•
Command-click on the new aligner.
•
Choose View Options... from the pop-up menu.
•
Choose Aligner Dimensions from the pop-up menu.
•
Change Rows to 2 Columns to 4.  Click Save & Close.

Add the first control.

•
Insert a number field with property name “index” into the upper left cell of the 2 x 4 aligner.
•
Double-click on the number field and set its value from 123 to 1.

Adding a morph view

Next you will add a morph view to the bottom part of Film Catalog.  A morph view is a view that can change forms depending on which object it is viewing.

•
Choose  Palette... in the Utilities menu.

The palette contains numerous different fields that can be inserted into an aligner.  They are described in Glyphic Codeworks Procedures Manual.

•
Drag morph from the Palette to the bottom part of Film Catalog.  Close the Palette.

At this point, the property that the morph view is attached to has the value of the unknown object.  Change that property to a script returning the item in the film folder indicated by the index property.

•
Command-click in the newly inserted morph field.
•
Choose Edit Script from the pop-up menu.
•
Edit the script to read:

return film-folder.list @ index.

•
Save and close the script editor.

If you switch Film Catalog to user mode, you will see that changing the index changes which film is displayed.  Note that the above script does not handle the error condition in which the index is too big or small.  In those cases, a debugger will open that you can just close.  A safer script would read:

if ((index < 1) or (index > film-folder.list.size))

then [ return ??? ].

return film-folder.list @ index.

Adding control buttons to Film Catalog

Now you will add four buttons to the Film Catalog.  Make sure it is in author mode.

•
Add a button to the upper right cell of the 2 x 4 aligner.
•
Command-click on the button, choose Rename Control... from the the pop-up menu.
•
Enter the string “Delete” in the resulting note.

Use the same procedure to add a button with the display string of “New” to the left of the delete button.  Add a button named “<<<“ below New and one named “>>>” below Delete.

Film Catalog should look something like this:

Writing scripts

The next step is to add scripts to the four buttons that you just added so that they perform the actions associated with their names.

These tips will be helpful in writing scripts:

•
The Templates menu in the script editor’s menu bar can be used to insert common script fragments (such as the if/then/else statement).

•
The error “Unknown property or local” is often caused by spelling errors.  You may have have a spelling error in the script or you may have misspelled the property name when you added its view.

•
Command-B or a selection to make the text bold

•
Command-P or a selection to make the text plain.

•
Command-I on a word or selection to make the text italic.  (Used for comments).

•
Typing words that begin with a capital letter will be inserted bold, and in lower case (except in quoted strings). 

The New Script

Make sure Film Catalog is in author mode before continuing.

•
Double-click on the New button.

The script editor named "Film Catalog.script-x" will open.  The script will already contain sample text.  You can delete all of it.

•
Edit its script so that it reads as follows (including all bolding and punctuation):

$ f.

f := new film.

film-folder.list insert f after index.

index := index + 1.

The first line of the script declares the local variable f.  The next line creates a new film, by sending the message new to the Film class, and assigns the new film to f.  The next two lines add f to the film-folder and increment index.

•
Click the Save button of the script editor to save the script.

If there are any errors in the script that prevent it from being saved, the error message will appear below the text of the Script Editor and the script’s text that caused the error will be selected.

•
Close the Script Editor.

You can switch Film Catalog to user mode and test that the button works.

The Delete script

Make sure Film Catalog is in author mode.

•
Double-click the Delete button.
•
Edit the script so that it reads:

$ size.

size := film-folder.list.size.
 if ((index < 1) or (index > size)) then [
 
tell user "There are no films to delete.".
 
return.

].

film-folder.list delete index.
 if index > film-folder.list.size then [

index := index - 1.

].

 First the local variable size is set to the number of films in the film-folder.  Next, the script checks that the index has an appropriate value and alerts the user if it does not.  Then the indexed film is deleted.  Finally, the index is decremented if it would have been too large.

•
Click the Save button of the script editor to save the script.

The Previous and Next Scripts

•
Edit the script for “<<<“ so that it reads:

index := index - 1.

if index < 1

then [ index := film-folder.list.size ].

•
Edit the script for “>>>“ so that it reads:

index := index + 1.

if index > film-folder.list.size

then [ index := 1 ].